Why do you instantiate another uidoc object? You get one "out of the box":
"Source" in the form Postopen event.
There's no need to declare and instantiate the NotesUIWorkspace nor a NotesUIDocument just to cover that. So, your Postopen code could just read:
Dim doc As NotesDocument
Set doc = Source.Document
I'm also somewhat confused as to how this relates to the agent code you detail...
--
http://www.benpoole.com